package com.wehgu.admin.controller;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wehgu.admin.common.BaseController;
import com.wehgu.admin.common.ResultTemplate;
import com.wehgu.admin.common.vo.UserInfoVO;
import com.wehgu.admin.config.security.dto.SecurityUser;

import com.wehgu.admin.config.security.impl.UserDetailsServiceImpl;
import com.wehgu.admin.entities.dto.UserPageQuery;
import com.wehgu.admin.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author generate by isMiao
 * @since 2022-01-24
 */
@Api(tags = "用户-接口")
@RestController
@RequestMapping("/sys_user")
public class SysUserController extends BaseController {

    @Resource
    private UserDetailsServiceImpl userDetailsService;

    @Resource
    private ISysUserService iSysUserService;

    @PostMapping(value = "/getCurrentUserInfo", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "获取当前登录用户信息", httpMethod = "POST", response = ResultTemplate.class, notes = "获取当前登录用户信息")
    public ResultTemplate getCurrentUserInfo(@RequestHeader(name = "X-Token") String token)
    {

        SecurityUser securityUser=userDetailsService.getUserByToken(token);
        UserInfoVO userInfoVO= new UserInfoVO();
        BeanUtil.copyProperties(securityUser.getCurrentUserInfo(),userInfoVO);

        return ResultTemplate.ok(200,"获取当前登录用户信息成功", userInfoVO);
    }

    @PostMapping(value = "/getUserPage", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "分页获取用户列表", httpMethod = "POST", response = ResultTemplate.class, notes = "分页获取用户列表")
    public ResultTemplate getUserPage(@RequestBody UserPageQuery input)
    {

        Page<UserInfoVO> page = new Page<>(input.getPage(), input.getLimit());

        List<UserInfoVO> userList = iSysUserService.selectUsers(page,input);

        return ResultTemplate.ok(200,"获取用户列表成功", userList);
    }


}
